package day02

import scala.collection.parallel.immutable.ParSeq

/**
  * Created by root on 2018/11/22.
  */
class CollectionMethod1 {

}

object CollectionMethod1{
  def main(args: Array[String]): Unit = {
    val list = List(1,2,3,4,5,6,6,6,6,6,6)
    val reduce: Int = list.reduceRight((x, y) => {
      println(x + "\t" + y)
      x + y
    })
    println(reduce)


    //多加一个初始值
    list.fold(5)((x,y)=>{
      println(x + "\t" + y)
      x+y
    })
    println("---------------------------")
    //val par: ParSeq[Int] = list.par
    //par.aggregate()
    //aggregate     = foldLeft(z)(seqop)
    // 前面是局部聚合，后面是全局聚合
    val aggregate: Int = list.aggregate(0)((x,y)=>{
      println(x + "\t" + y+"*")
      x+y
    },(x,y)=>{
      println(x + "\t" + y)
      x+y
    })

    println(aggregate)


  }
}
